// pages/start/index.js
var qcloud = require('../../vendor/wafer2-client-sdk/index')
var config = require('../../config')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    indicatorDots: false,
    autoplay: true,
    current: 0,
    interval: 3000,
    duration: 1000,
    circular: true,
    canSkip:false,
    startImgs: []
    // startImgs: [
    //   {typevalue:'images/start-xiaoxue.png'},
    //   {typevalue:'images/start-daxue.png'},
    //   { typevalue: 'images/start-dongzhi.png'},
    //   { typevalue: 'images/start-go.png', def1: true}
    // ]

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    var that = this
    qcloud.request({
      url: `${config.service.host}/weapp/getSysParams`,
      //method:'POST',
      data: { bigtype: 'SYSTEM', smalltype: 'STARTPAGE' },
      login: false,
      success(result) {
        if (result.data.data.status == '0') {
          that.setData({
            startImgs: result.data.data.msg
          })
        } else {
          console.log(JSON.stringify(result.data.data));
          that.bindSkip()
        }
      },
      fail(error) {
        console.log('request fail', error);
        that.bindSkip()
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // console.log(this) 
    // if (this.options.test1) {
    //   this.goIndex()
    // }

    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  bindchange(e) {
    //console.log(e.detail.current)

    //if ((e.detail.current == this.data.startImgs.length - 1)&&this.data.startImgs[e.detail.current].isGo) {
    if (this.data.startImgs[e.detail.current].def1) {
      this.setData({
        autoplay: false
      })
    }
  },
  bindload(e) {
    setTimeout(this.bindSkip, this.data.startImgs.length * this.data.interval)
    this.setData({
      canSkip: true
    })
    //console.log("load"+e)
  },
  bindSkip() {
    //校验分支路径
    this.goIndex()
  },
  goIndex() {
    wx.switchTab({
      url: '/pages/main/single'
    })
  },
  goLogin() {
    wx.redirectTo({
      url: '/pages/start/index?test1=vale1&test2=value2'
    })
  }
})